package org.zerg.controller.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zerg.dto.Page;
import org.zerg.entity.Order;
import org.zerg.service.OrderService;

@RequestMapping("order")
@Controller
public class OrderWebController {

	@Autowired
	private OrderService orderService;
	
	@Autowired
	private HttpSession session;
	
	@RequestMapping("/list")
	public String getOrderAll(@RequestParam("page")int page){
		List<Order> list = orderService.getOrderAll(page);
		Page pa = orderService.pageMessage(page);
		session.setAttribute("list", list);
		session.setAttribute("page", pa);
		return "/order";
	}
	
	@ResponseBody
	@RequestMapping("/getDateil")
	public Order getOrderDateil(@RequestParam("id")int id){
		Order order = orderService.getOrderById(id);
		return order;
	}
	
	@RequestMapping("/status")
	public String setStatus(@RequestParam("classId")int classId,@RequestParam("page")int page,@RequestParam("id")int id){
		orderService.setStatus(classId,id);
		return "redirect:/order/list?page="+page;
	}
	
}
